﻿//-----------------------------------------------------------------------
// <copyright file="AttributeNodeCollectionExtension.cs" company="COMPANY">
//     Copyright (c) COPYRIGHT. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace CodeQualityExtension.Framework
{
    using System.Linq;
    using Microsoft.FxCop.Sdk;
    
    /// <summary>
    /// Extensions for <see cref="Microsoft.FxCop.Sdk.AttributeNodeCollection"/>
    /// </summary>
    public static class AttributeNodeCollectionExtension
    {
        /// <summary>
        /// Looks for <see cref="Microsoft.FxCop.Sdk.AttributeNode"/> with matching attribute name
        /// </summary>
        /// <param name="attributes">Collection of AttributeNode items to search</param>
        /// <param name="attributeName">Full name of attribute class (including namespace)</param>
        /// <returns>AttributeNode instance or null if none is found</returns>
        public static AttributeNode FindByName(
            this AttributeNodeCollection attributes, 
            string attributeName)
        {
            var result = attributes.FirstOrDefault(
                attribute => attribute.Type.FullName == attributeName);

            return result;
        }
    }
}
